/**
 * 基础菜单 商品管理
 */
<template>
<div>
  <!-- 面包屑导航 -->
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/main' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>农户审核列表</el-breadcrumb-item>
  </el-breadcrumb>
  <!-- 搜索筛选 -->
  <el-form :inline="true" :model="formInline" class="user-search">
    <my-input v-model="formInline.name" placeholder="输入产品名称"></my-input>
    <my-select v-model="formInline.auditStatus" placeholder="审批状态：" :options="statusOptions" />
    <el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
    </el-form-item>
  </el-form>
  <!--列表-->
  <el-table  align="center" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
    <el-table-column align="center" label="序号" sortable type="index" width="100" />
    <el-table-column align="center" label="产品名称" prop="name" />
    <el-table-column align="center" label="注册时间" prop="createTime"  />
    <el-table-column align="center" label="审批状态" >
        <template v-slot="scope"><el-tag size="medium">{{ statusObj[scope.row.auditStatus]}}</el-tag></template>
      </el-table-column>
    <el-table-column align="center" label="备注" prop="remark" />
    <el-table-column align="center" label="操作"  fixed="right">
      <template slot-scope="scope">
        <el-button size="mini" type="info" @click="handleDetails(scope.$index, scope.row)">查看详情</el-button>
      </template>
    </el-table-column>
  </el-table>
  <!-- 分页组件 -->
  <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
</div>
</template>

<script>
import Pagination from '../../components/Pagination'
import { mapToOptions } from '@/utils'
const statusObj = {
  WAIT_AUDIT: '待审批',
  COMPLETE_AUDIT: '已通过',
  COMPLETE_REFUSE: '已拒绝'
}
export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      listData: [], //用户数据
      statusObj: {
        NOT_AUDIT: '待审批',
        AUDIT_FAIL: '已通过',
        AUDIT_PASS: '已拒绝'
      },
      statusOptions: mapToOptions(statusObj),
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      },
      formInline: {
        page: 1,
        limit: 10,
        varLable: '',
        varName: '',
        token: localStorage.getItem('logintoken')
      },
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取公司列表
    getdata(parameter) {
      this.loading = true
      // 模拟数据开始
      let res = {
        code: 0,
        msg: null,
        count: 5,
        data: [{
            name: '李白',
            mobile: 13065478545,
            createTime: 1521062371000,
            auditStatus: 'AUDIT_PASS',
            remark: 1526700200000,
          },
          {
            name: '后裔',
            mobile: 13065478545,
            createTime: 1521062371000,
            auditStatus: 'AUDIT_PASS',
            remark: 1526700200000,
          },
          {
            name: '妲己',
            mobile: 13065478545,
            createTime: 1521062371000,
            auditStatus: 'AUDIT_PASS',
            remark: 1526700200000,
          },
          {
            name: '嫦娥',
            mobile: 13065478545,
            createTime: 1521062371000,
            auditStatus: 'AUDIT_PASS',
            remark: 1526700200000,
          }
        ]
      }
      this.loading = false
      this.listData = res.data
      this.pageparm.currentPage = this.formInline.page
      this.pageparm.pageSize = this.formInline.limit
      this.pageparm.total = res.count
      // 模拟数据结束

      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
      // deptList(parameter)
      //   .then(res => {
      //     this.loading = false
      //     if (res.success == false) {
      //       this.$message({
      //         type: 'info',
      //         message: res.msg
      //       })
      //     } else {
      //       this.listData = res.data
      //       // 分页赋值
      //       this.pageparm.currentPage = this.formInline.page
      //       this.pageparm.pageSize = this.formInline.limit
      //       this.pageparm.total = res.count
      //     }
      //   })
      //   .catch(err => {
      //     this.loading = false
      //     this.$message.error('菜单加载失败，请稍后再试！')
      //   })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    handleDetails(item) {
      this.$router.push({ name: 'auditDetails', params: { id: item.id } })
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}

.userRole {
  width: 100%;
}
</style>
